package com.game.desktop.Maze.Tests;

import java.util.ArrayList;
import java.util.Iterator;

import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.game.Maze.Objects.Room;
import com.game.Maze.Renderers.CameraRenderer;
import com.game.Maze.Renderers.IRenderer;
import com.game.Maze.Renderers.RoomRenderer;

/**
 * Тест рендера комнаты
 *
 */
public class TestRoomRenderer implements ApplicationListener
{
  Room m_Room1;
  Room m_Room2;
  ArrayList<IRenderer> m_RoomRenderers = new ArrayList<IRenderer>();
  private CameraRenderer m_CameraRenderer = null;
  SpriteBatch m_Batch;
  
  @Override
  public void create()
  {
    m_Batch = new SpriteBatch();
    
    // Создаем рендерер камеры
    m_CameraRenderer = new CameraRenderer();
    m_CameraRenderer.create(0, 0);
    
    m_Room1 = new Room();
    m_Room2 = new Room();
    m_Room2.setUsed();
    
    IRenderer roomRenderer;
    
    roomRenderer = new RoomRenderer(m_Room1); 
    roomRenderer.create(0, 0);
    m_RoomRenderers.add(roomRenderer);

    roomRenderer = new RoomRenderer(m_Room2); 
    roomRenderer.create(5, 5);
    m_RoomRenderers.add(roomRenderer);
    
    m_CameraRenderer.moveTo(3, 3);
  }

  @Override
  public void resume()
  {
  }

  @Override
  public void render()
  {
    Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

    m_Batch.begin();
    m_CameraRenderer.render(m_Batch);
    
    Iterator<IRenderer> renderes = m_RoomRenderers.iterator();
    while (renderes.hasNext())
      renderes.next().render(m_Batch);
    m_Batch.end();
  }

  @Override
  public void resize(int width, int height)
  {
    m_CameraRenderer.resize(width, height);
  }

  @Override
  public void pause()
  {
  }

  @Override
  public void dispose()
  {
  }
}
